import moment from 'moment'
// getters

export const state = {
  userName: "",
  profile:{
  	searchKeyList:[],
  	currentSearchIndex:0
  }
};
export const getters = {
  enumFormat: (state) => (arrary, key) => {
    return format(arrary, key)
  },
  timeFormat: (state) => (keylong) => {
    return moment(keylong*1000).format("YYYY-MM-DD-HH:mm:ss")
  },
  addSearchKeyList: (state) => (searchKeyList,w) => {
  	  state.profile.searchKeyList=searchKeyList.concat({name:w})
    return state.profile.searchKeyList
  },
  delSearchKeyList: (state) => () => {
  	  state.profile.searchKeyList.splice(0)
    return state.profile.searchKeyList
  },
  setCurrentSearchIndex: (state) => (w) => {
  	 state.profile.currentSearchIndex=w
    return state.profile.currentSearchIndex
  },
};

const format = function (array, key) {
  for (let item of array) {
    if (item.key === key) {
      return item.value
    }
  }
  return null
}

